package com.wisecoach.gatewayplus.event;

/**
 * {@code @author:} wisecoach
 * {@code @date:} 2023/6/15 上午3:30
 * {@code @version:} 1.0.0
 */
public abstract class AbstractFilteredBlockEventListener implements FilteredBlockEventListener {

    protected final String name;
    protected final ListenerResumeType resumeType;

    protected long current = 0;

    protected AbstractFilteredBlockEventListener(String name, ListenerResumeType resumeType) {
        this.name = name;
        this.resumeType = resumeType;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public long getNext() {
        return current;
    }

    @Override
    public void startAt(long startNumber) {
        this.current = startNumber;
    }

    @Override
    public void onEvent(FilteredBlockEvent event) {
        handleEvent(event);
        next();
    }

    @Override
    public ListenerResumeType getListenerResumeType() {
        return resumeType;
    }

    protected abstract void handleEvent(FilteredBlockEvent event);

    protected void next() {
        this.current += 1;
    }

}
